package com.ch05.service;

import com.ch05.mapper.DormitoryMapper;
import com.ch05.pojo.Dormitory;
import com.ch05.utils.MyBatisSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * @ClassName DormitoryService
 * @Description TODO
 * @Author Kx
 * @Date 2025/4/23 15:37
 * @Version 1.0
 */
public class DormitoryService {
    /**
     * @author: kx
     * @date: 2025/4/23 20:03
     * @return java.util.List<com.ch05.pojo.Dormitory>
     * @description: 动态查询所有宿舍信息
    */
    public List<Dormitory> listDormitory(Map<String, Object> params) {
        // 获取sqlSession对象
        try (SqlSession sqlSession = MyBatisSqlSessionFactory.getSqlSession()) {
            return sqlSession.getMapper(DormitoryMapper.class).listDormitory(params);
        }
    }

    /**
     * @param ids : 宿舍id集合
     * @return java.util.List<com.ch05.pojo.Dormitory>
     * @author: kx
     * @date: 2025/4/23 20:18
     * @description: 根据id集合查询宿舍信息
     */
    public List<Dormitory> listDormitoryById(List<Integer> ids) {
        // 获取sqlSession对象
        try (SqlSession sqlSession = MyBatisSqlSessionFactory.getSqlSession()) {
            return sqlSession.getMapper(DormitoryMapper.class).listDormitoryById(ids);
        }
    }

    /**
     * @param dormitory : 宿舍信息
     * @author: kx
     * @date: 2025/4/23 20:22
     * @description: 动态修改宿舍信息
     */
    public void updateDormitory(Dormitory dormitory) {
        // 获取sqlSession对象
        try (SqlSession sqlSession = MyBatisSqlSessionFactory.getSqlSession()) {
            sqlSession.getMapper(DormitoryMapper.class).updateDormitory(dormitory);
        }
    }
}
